package com.noahplat.oufu.utils;

/**
 * rabbit生产者
 */

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @ClassName: MQUtil
 * @Description: rabbit MQ工具类
 * @Author 李景星
 * @Date 2021/6/8
 * @Version 1.0
 */
@Component
public class MQUtil {

    @Autowired
    private RabbitTemplate rabbitTemplate;


    /**
     * 直连型交换机消息投递
     * @param exchange 交换机名称
     * @param routing 路由键
     * @param msg 消息
     * @return
     */
    public boolean sendDirectMsg(String exchange, String routing, Object msg){
        try {
            rabbitTemplate.convertAndSend(exchange, routing, msg);
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }

    }
}